package com.galudisu

import akka.actor.{Actor, ActorLogging, Terminated}
import com.galudisu.jooq.PoolableFactory

import scala.util.Try

class Worker[T](objectFactory: PoolableFactory[T]) extends Actor with ActorLogging{

	private val pooledObject = objectFactory.create

        def receive = {
          case Job(fn: Function1[T, _]) =>
            context.watch(sender())
            sender ! Try(fn(pooledObject))
          case Terminated(monitor) =>
            context.stop(monitor)
        }

}
